﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Reviews_Detail : System.Web.UI.Page
{
    private Logging objLogging = new Logging();
    private string strApplicationName = MethodBase.GetCurrentMethod().DeclaringType.Name;
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            using (ProjectASPEntities myEntities = new ProjectASPEntities())
            {
                List<int?> reviews = myEntities.getReview(User.Identity.Name, int.Parse(Request.QueryString[0])).ToList();
                if (reviews.Capacity > 0)
                {
                    hideRating();
                    Label1.Visible = true;
                    Label1.Text = "You already reviewed this product";
                }
            }
            if (!User.Identity.IsAuthenticated)
            {
                hideRating();
            }
        }
        catch (Exception ex)
        {
            objLogging.WriteLine(strApplicationName, ex.Message);
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid)
            {
                using (ProjectASPEntities myEntities = new ProjectASPEntities())
                {
                    myEntities.insertReview(User.Identity.Name, int.Parse(Request.QueryString[0]), Rating1.CurrentRating, DescriptionText.Text);
                }
                hideRating();
                GridView1.DataBind();
            }
        }
        catch (Exception ex)
        {
            objLogging.WriteLine(strApplicationName, ex.Message);
        }
    }

    private void hideRating()
    {
        Rating1.Visible = false;
        Label1.Visible = false;
        Label2.Visible = false;
        DescriptionText.Visible = false;
        Button1.Visible = false;
    }
}